<?php

/**
 * @file z_cefpdf.php
 * @brief Clase para generar un anclas
 * @author DyrTechnologies
 * @version V 1.0
 * @date Tue Dec 18 2007
 *
 *  Part of the CEFIRO dynamic web framework project
 *
 *  Copyright (C) 2007  Dyr technologies http://dyrtech.com.ve
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

if (!defined('CEFIRO')) define("CEFIRO",substr(__FILE__,0,strpos(__FILE__,"cefiro"))."cefiro/widgets/cefiro.php");
require_once(CEFIRO);
require_once(CEF_PDF);
require_once(CEF_BUTTON3D);

function getCefPdf($args){

  global $smarty;

  $srcDisplay = '
for($i = 0 ; $i < 40 ; $i++){
  $table[$i]["number"] = $i + 1;
  $table[$i]["isOdd"] = $i % 2 ? "That\'s True" : "That\'s False";
  $fontcolor[$i] = $i % 2 ? "#0000FF" : "#00FF00";
}

$titles = array("Number", "Is Odd");
$keys	= array("number", "isOdd");

$smarty->assign("query", cefpdf::tables($table, $titles, $keys, "verdana", 8,
                                        NULL, NULL, NULL, NULL, NULL, NULL,
                                        NULL, NULL, $fontcolor));
$smarty->assign("title", mb_convert_encoding("Numbers", "ISO-8859-1", "UTF-8"));

$input_template = dirname(__FILE__)."/z_cefpdf.tpl";
$pdf = new cefpdf("sample", $input_template, "cefpdf_sample.pdf", "Click to see PDF");';

  $tplDisplay = '
<html>
  <head>
    <meta http-equiv=\'Content-Type\' content=\'text/html; charset=ISO-8859-1\'>
	  <title> {$title} </title>
	</head>

	<body>
	  <center><h3> {$title} </h3></center>
	  <hr/>
	  <br/>
	  {$query}
	</body>
</html>';


  $someButton = new button3d('generarBoton', 'Click to see PDF');
  $someButton->set_onClic("zajax.call('zajax/cefpdf/z_cefpdf.php','showPDF', null);");

  $widgetDisplay = $someButton->display_button3d(true)."<br/><div id='sample'></div>";

  addAssign('widgetTitle', 'innerHTML', "<p class='title_blue'>CefPDF</p>");
  addAssign('widgetDisplay', 'innerHTML', $widgetDisplay);

  addAssign('srcTitle', 'innerHTML', "<p class='title_red'>Source</p>");
  addAssign('srcDisplay', 'innerHTML', '<p><pre>'.$srcDisplay.'</pre></p>');

  $tplDisplay = str_replace('<', '&lt;', $tplDisplay);
  $tplDisplay = str_replace('>', '&gt;', $tplDisplay);

  addAssign('tplTitle', 'innerHTML', "<p class='title_green'>Smarty Template</p>");
  addAssign('tplDisplay', 'innerHTML', '<pre>'.$tplDisplay.'</pre>');

  eval($srcDisplay);

	return processResponse();
}

function showPDF(){

  global $smarty;

  for($i = 0 ; $i < 40 ; $i++){
    $table[$i]['number'] = $i + 1;
    $table[$i]['isOdd'] = $i % 2 ? 'That\'s True' : 'That\'s False';
    $fontcolor[$i] = $i % 2 ? '#0000FF' : '#00FF00';
  }

  $titles = array('Number', 'Is Odd');
  $keys	= array('number', 'isOdd');

  $smarty->assign("query", cefpdf::tables($table, $titles, $keys, "verdana", 8,
                                          NULL, NULL, NULL, NULL, NULL, NULL,
                                          NULL, NULL, $fontcolor));

  $smarty->assign("title", mb_convert_encoding('Numbers', 'ISO-8859-1', 'UTF-8'));

  /* Nota: si se asigna title antes que query entonces ocurre algo raro */
  $input_template = dirname(__FILE__).'/z_cefpdf.tpl';

  $pdf = new cefpdf('sample', $input_template, 'cefpdf_sample.pdf', 'Click to see PDF');

	addScript($pdf->display(DIRECT_LINK, true));

	return processResponse();
}

?>